#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int n, fruits[20000], strength = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> fruits[i];
	}
	sort(fruits, fruits + n);
	for (int i = 0; i < n - 1; i++)
	{
		strength +=  fruits[i] + fruits[i + 1];
		fruits[i + 1] = fruits[i] + fruits[i + 1];
		int j = i + 1, temp = fruits[i + 1];
		while (true)
		{
 			if (fruits[i + 1] < fruits[j]  || j > n - 1 ) break;
			j++;
		}  
		for (int k = i + 1; k < j - 1; k++)
		{
			fruits[k] = fruits[k + 1];
		}
		fruits[j - 1] = temp;
	}
	cout << strength;
	return 0;
}